import { ExtSkuTpl } from "~/extend";
import { BIGINT_PG, ExtIdTuple, INTEGER_PG } from "~/db.pg";

import { ExtOwner } from "@/stream-user/core.define";

import { Stockable } from "@/river-stock/core.define";
import { TonOrderGroup } from "@/river-ton/schema.order";
import { CommonStock } from "@/river-stock/schema.notch";

/** 商品库存分组（例如：有花镀锌 > 1000 > 1.0*1250*2500）*/
export type StockNode = ExtIdTuple &
  ExtOwner &
  ExtSkuTpl &
  Stockable & {
    layer: INTEGER_PG;
    timeStart: BIGINT_PG;
    timeEnd: BIGINT_PG;

    isRootNode: boolean;
    refRootNodeId: null | StockNode["id"];
    justRootNode?: StockNode;

    refParentNodeId: null | StockNode["id"];
    justParentNode?: StockNode;
  } & {
    joinStockNodeLinkList?: StockNodeLink[];
    joinCommonStockList?: CommonStock[];
  };

/** 订单集合/名称分类（商品推送的时候，每一个名称分类都需要具有权限）*/
export type StockNodeLink = ExtIdTuple &
  ExtOwner & {
    refTonOrderGroupId: TonOrderGroup["id"];
    justTonOrderGroup?: TonOrderGroup;
    refStockNodeId: StockNode["id"];
    justStockNode?: StockNode;
  };
